#include<func.h>
int main(int argc,char* argv[])
{
    ARGS_CHECK(argc,3)
    int sfd=socket(AF_INET,SOCK_STREAM,0);
    ERROR_CHECK(sfd,-1,"socket")
    printf("sfd=%d\n",sfd);
    struct sockaddr_in ser_addr;
    bzero(&ser_addr,sizeof(ser_addr));
    ser_addr.sin_family=AF_INET;
    ser_addr.sin_port=htons(atoi(argv[2]));
    ser_addr.sin_addr.s_addr=inet_addr(argv[1]);
    int ret=bind(sfd,(struct sockaddr*)&ser_addr,sizeof(ser_addr));
    ERROR_CHECK(ret,-1,"bind")
    ret=listen(sfd,10);
    ERROR_CHECK(ret,-1,"listen");
    struct sockaddr_in client_add;
    bzero(&client_add,sizeof(client_add));
    socklen_t addr_len=sizeof(client_add);
    int new_sfd=accept(sfd,(struct sockaddr *)&client_add,&addr_len);
    ERROR_CHECK(new_sfd,-1,"accept")
    printf("client ip=%s,port=%d\n",inet_ntoa(client_add.sin_addr),ntohs(client_add.sin_port));
    char buf[128]={0};
    ret=recv(new_sfd,buf,sizeof(buf),0);
    ERROR_CHECK(ret,-1,"recv")
    printf("I am server,gets=%s\n",buf);
    send(new_sfd,"world",5,0);
    close(new_sfd);
    close(sfd);

    return 0;


}